Skip to content

fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3103

Closed
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-3097-upload-poll-timeout
Closed

fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3103
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-3097-upload-poll-timeout

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 19, 2026

Summary

Fixes #3097: `vector_stores.files.upload_and_poll()` hangs indefinitely when a vector store file stays stuck at `status="in_progress"`.

Root Cause

The `poll()` method uses an unbounded `while True:` loop with no timeout mechanism. If the OpenAI API gets into a state where a file never leaves `in_progress`, the call will block forever.

Fix

Added an optional `poll_timeout_ms: float | None` parameter to all six polling methods:

  • `Files.poll()` / `AsyncFiles.poll()`
  • `Files.create_and_poll()` / `AsyncFiles.create_and_poll()`
  • `Files.upload_and_poll()` / `AsyncFiles.upload_and_poll()`

When `poll_timeout_ms` is set and the elapsed time (tracked with `time.monotonic()`) exceeds the limit while the file is still `in_progress`, a `TimeoutError` is raised with a descriptive message identifying the stuck file. When not set (default `None`), behavior is unchanged — fully backwards compatible.

Usage

# Raises TimeoutError if still in_progress after 30 seconds
file = client.vector_stores.files.upload_and_poll(
    vector_store_id="vs_abc",
    file=open("data.pdf", "rb"),
    poll_timeout_ms=30_000,
)

Changes

  • src/openai/resources/vector_stores/files.py: Added import time, added poll_timeout_ms parameter and timeout check logic to all six polling methods (sync + async)

…efinite hang

Fixes openai#3097: upload_and_poll() and poll() would hang indefinitely when a
vector store file stays stuck in 'in_progress' status.

Added poll_timeout_ms parameter (float | None) to:
- Files.poll() / AsyncFiles.poll()
- Files.create_and_poll() / AsyncFiles.create_and_poll()
- Files.upload_and_poll() / AsyncFiles.upload_and_poll()

When poll_timeout_ms is set and elapsed time exceeds it, raises TimeoutError
with a descriptive message. Uses time.monotonic() for accurate elapsed tracking.
@xodn348 xodn348 requested a review from a team as a code owner April 19, 2026 18:30
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f14ec39c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +381 to +385
if is_given(poll_timeout_ms) and poll_timeout_ms is not None:
if (time.monotonic() - start) * 1000 >= poll_timeout_ms:
raise TimeoutError(
f"Vector store file {file_id!r} is still in_progress after {poll_timeout_ms:.0f}ms"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clamp poll sleep to remaining timeout

In Files.poll(), the timeout check runs before self._sleep(...), so when poll_interval_ms (or the openai-poll-after-ms header) is larger than the remaining budget, the call sleeps past the deadline and only raises TimeoutError on the next iteration. That means a configured timeout can be exceeded by a large margin (e.g., 30s timeout with a 60s poll interval), which weakens the behavior this change is meant to guarantee; the async poll path uses the same pattern.

Useful? React with 👍 / 👎.

@xodn348
Copy link
Copy Markdown
Author

xodn348 commented Apr 20, 2026

Closing duplicate — #3102 is the canonical PR.

@xodn348 xodn348 closed this Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector_stores.files.upload_and_poll() can hang indefinitely with file status stuck at in_progress

1 participant